package com.pirestupppai.widgets.dialog;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.adapter.PsListAdapter;
import com.pirestupppai.base.BaseDialog;
import com.pirestupppai.common.Constant;
import com.pirestupppai.ui.activity.MainActivity;
import com.pirestupppai.ui.activity.PsListActivity;
import com.pirestupppai.ui.activity.SelectPictureActivity;
import com.pirestupppai.ui.activity.VideoListActivity;
import com.pirestupppai.ui.activity.VideoRecordActivity;
import com.pirestupppai.utils.WeakReferenceHandler;

import butterknife.BindView;

/**
 *  发布Dialog
 */

public class ReleaseImageOrVideoDialog extends BaseDialog {

    @BindView(R.id.close_btn)
    ImageView closeBtn;
    @BindView(R.id.release_origin_img_tv)
    TextView releaseOriginImgBtn;
    @BindView(R.id.release_work_img_tv)
    TextView releaseWorkImgBtn;
    @BindView(R.id.release_video_tv)
    TextView releaseVideoBtn;
    @BindView(R.id.release_tutti_tv)
    TextView releaseTuttiBtn;
    @BindView(R.id.operation_layout)
    LinearLayout operationLayout;
    @BindView(R.id.content_view)
    RelativeLayout contentView;

    private WeakReferenceHandler mHandler;

    public ReleaseImageOrVideoDialog(Context context) {
        super(context, R.style.CustomDialogStyle);
        this.mContext = context;
        mHandler = new WeakReferenceHandler((MainActivity) context);


        Window menuWindow = getWindow();
        menuWindow.getAttributes().width = mContext.getResources().getDisplayMetrics().widthPixels;
        menuWindow.getAttributes().height = mContext.getResources().getDisplayMetrics().heightPixels;
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.dialog_release_image_or_video;
    }

    @Override
    protected boolean atBottom() {
        return true;
    }

    @Override
    protected void initViews() {
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) operationLayout.getLayoutParams();
        layoutParams.setMargins(0 , Constant.HEIGHT_OF_SCREEN / 2, 0, 0);
        operationLayout.setLayoutParams(layoutParams);
    }

    @Override
    protected void initListeners() {
        releaseOriginImgBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, SelectPictureActivity.class);
                intent.putExtra(Constant.IntentKey.RELEASE_TYPE, Constant.SELECT_TYPE_ASK);
                mContext.startActivity(intent);


                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismiss();
                    }
                }, 1000);
            }
        });

        releaseWorkImgBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, PsListActivity.class);
                intent.putExtra(Constant.IntentKey.PS_TYPE, PsListAdapter.PS_TYPE_INPROGRESS);
                mContext.startActivity(intent);

                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismiss();
                    }
                }, 1000);
            }
        });

        releaseVideoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext, VideoRecordActivity.class));

                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismiss();
                    }
                }, 1000);
            }
        });

        releaseTuttiBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext, VideoListActivity.class));

                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismiss();
                    }
                }, 1000);
            }
        });

        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
